use crate::solution::Solution;

impl Solution {
    pub fn num_rook_captures(board: Vec<Vec<char>>) -> i32 {
        let   (mut r_pos_i,mut r_pos_j) = (0, 0);
        'outer:
        for (i,row) in board.iter().enumerate() {
            for (j,&ch) in row.iter().enumerate() {
                if ch == 'R' {
                    r_pos_j = j as i32;
                    r_pos_i = i as i32;
                    break 'outer;
                }
            }
        };
        let mut ans =0;
        let mut ti =r_pos_i-1;
        while  ti>=0{
            match board[ti as usize][r_pos_j as usize]{
                'B' => break,
                'p' => {
                    ans+=1;
                    break;
                },
                _ => ti-=1
            }
        };
        ti=r_pos_i+1;
        while  ti<board.len() as i32{
            match board[ti as usize][r_pos_j as usize]{
                'B' => break,
                'p' => {
                    ans+=1;
                    break;
                },
                _ => ti+=1
            }
        };
        let mut tj =r_pos_j-1;
        while  tj>=0{
            match board[r_pos_i as usize][tj as usize]{
                'B' => break,
                'p' => {
                    ans+=1;
                    break;
                },
                _ => tj-=1
            }
        };
        tj=r_pos_j+1;
        while  tj<board[0].len() as i32{
            match board[r_pos_i as usize][tj as usize]{
                'B' => break,
                'p' => {
                    ans+=1;
                    break;
                },
                _ => tj+=1
            }
        };
        ans

    }
}

// #[cfg(test)]
// mod tests {
//     use super::Solution;
//     #[test]
//     fn test_num_rook_captures() {
//         Solution::num_rook_captures(vec![])
//     }
// }
